﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VCC.Lib.Helpers;
namespace VCC.Lib.Common
{
    public class LinkUtils
    {
        public static string UrlImageOrDefault(string imagepath)
        {
            if (string.IsNullOrEmpty(imagepath)) return "/Images/Logo/nophoto.png";
            else return imagepath;
        }
        public static string ShopImageOrDefault(string imagepath)
        {
            if (string.IsNullOrEmpty(imagepath)) return "/Images/noavatar.jpg";
            else return imagepath;
        }
        public static readonly string domain = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
        public static string AvataOrDefault(string avataPaht)
        {
            if (string.IsNullOrEmpty(avataPaht)) return "/Images/noavatar.gif";
            else return avataPaht;
        }
        public static string UrlAdIndexDefault(string ParentCateName, string ChildenCateName, string SuburbName)
        {
            StringBuilder urlLink = new StringBuilder();
            string pcate = string.Empty;
            string chlcate = string.Empty;
            string subname = string.Empty;
            if (!string.IsNullOrEmpty(ParentCateName))
            {
                pcate= TextHelper.ToUrlFriendly(ParentCateName);
                urlLink.Append("/" + pcate);
            }
            if (!string.IsNullOrEmpty(ChildenCateName))
            {
                chlcate = TextHelper.ToUrlFriendly(ChildenCateName);
                urlLink.Append("/" + chlcate);
            }
            if (!string.IsNullOrEmpty(SuburbName))
            {
                subname = TextHelper.ToUrlFriendly(SuburbName);
                urlLink.Append("/" + subname);
            }
            
            return urlLink.ToString();
        }
        public static string UrlAdIndexDefault(string demandShortName, string CateShortName, string cityShortName,string countryShortName, string AdtributeShortName, string adtributeValueShortName, int cusTypeId)
        {
            var link = string.Format("/{0}/{1}/{2}/{3}/{4}/{5}", string.IsNullOrEmpty(demandShortName) ? "mua-ban" : demandShortName,
                string.IsNullOrEmpty(CateShortName) ? "hang-hoa" : CateShortName, string.IsNullOrEmpty(cityShortName) ? "Tat-ca" : cityShortName + "-" + countryShortName,
                string.IsNullOrEmpty(AdtributeShortName) ? "thong-tin" : AdtributeShortName,
                string.IsNullOrEmpty(adtributeValueShortName) ? "lien-he" : adtributeValueShortName, cusTypeId > 0 ? cusTypeId : 0);
            return link;
        }
        public static string UrlAdDetails(string titleName, int id)
        {
            string url = string.Format("/{0}_{1}.html", TextHelper.ToUrlFriendly(titleName), id.ToString());
            return url;
        }
    }
}
